package light.head.dao.oa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.ReimburseCategory;
@Service
public class ReimburseCategoryDAO extends BaseDAO<ReimburseCategory, Integer>{
	
	public RESULT findByMapOc(List<Integer> ocs,Map<String, String> map, PageBean pb) {
		StringBuffer hql = new StringBuffer(" FROM ReimburseCategory rc WHERE rc.oc IN (");
		List<Object> list = new ArrayList<Object>();
		for (Integer i : ocs) {
			hql.append("?,");
			list.add(i);
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		if (map != null) {
			String name = map.get(Parm.NAME);			//车辆类型
			String cn = map.get(Parm.CN);			//车牌号
			String on = map.get(Parm.ON);		//状态
			if (null != name && !"".equals(name)) {
				hql.append(" AND rc.name LIKE ?");
				list.add("%" + name + "%");
			}if (isNotNull(cn)) {
				list.add("%" + cn + "%");
				hql.append(" AND rc.cu IN (SELECT ui.code FROM UserInfo ui WHERE ui.realName LIKE ?)");
			}if (isNotNull(on)) {
				list.add("%" + on + "%");
				hql.append(" AND rc.oc IN (SELECT o.code FROM Organ o WHERE o.name LIKE ?)");
			}
		}
		
		hql.append(" ORDER BY rc.code DESC");
		return findToPageBean(hql.toString(), pb, list);
	}

}
